package jsyf.oa.web.system;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.fastjson.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.RoleRightConfigLogFacade;

@Api(value = "职位权限配置日志接口", description = "职位权限配置日志接口")
@Controller
@RequestMapping("/roleRightConfigLog")
public class RoleRightConfigLogController {
    @Resource
    private RoleRightConfigLogFacade rolerightconfiglogFacade;

    @RequestMapping(value = "/save.json", method = RequestMethod.POST)
    public void save(HttpServletResponse response, @RequestBody String jsonData) {
        String result = rolerightconfiglogFacade.save(jsonData);
        if(!StringUtils.isEmpty(result)){
            JSONObject jsonResult = new JSONObject();
            jsonResult.put("id",result);
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonResult));
        }else{
            ResponseUtils.putJsonResponse(response,BaseUtils.errorrRespond("保存日志失败！"));
        }
    }

    @RequestMapping(value = "/getLogList.json", method = RequestMethod.POST)
    public void getLogList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj_params = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject records;
        String requestPage;
        String pageSize;
        if (obj_params.containsKey("requestPage") && obj_params.containsKey("pageSize")) {
            requestPage = obj_params.getString("requestPage");
            pageSize = obj_params.getString("pageSize");
            records = this.rolerightconfiglogFacade.getLogList("", Integer.parseInt(requestPage), Integer.parseInt(pageSize));
        } else {
            requestPage = "1";
            pageSize = Integer.MAX_VALUE + "";
            records = this.rolerightconfiglogFacade.getLogList("", Integer.parseInt(requestPage), Integer.parseInt(pageSize));
        }
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }

    }

}
